# 环境配置测试脚本
# 用于验证开发和生产环境的数据库配置是否正确加载

Write-Host "=== 环境配置测试 ===" -ForegroundColor Green

# 测试开发环境配置
Write-Host "`n1. 测试开发环境配置..." -ForegroundColor Yellow
$env:ASPNETCORE_ENVIRONMENT='Development'

# 运行配置测试
try {
    $output = dotnet run --configuration Release --no-build -- --test-config 2>&1
    Write-Host "开发环境配置测试成功!" -ForegroundColor Green
    Write-Host "输出: $output" -ForegroundColor Gray
} catch {
    Write-Host "开发环境配置测试失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试生产环境配置  
Write-Host "`n2. 测试生产环境配置..." -ForegroundColor Yellow
$env:ASPNETCORE_ENVIRONMENT='Production'

try {
    $output = dotnet run --configuration Release --no-build -- --test-config 2>&1
    Write-Host "生产环境配置测试成功!" -ForegroundColor Green
    Write-Host "输出: $output" -ForegroundColor Gray
} catch {
    Write-Host "生产环境配置测试失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 显示配置文件内容
Write-Host "`n3. 配置文件内容:" -ForegroundColor Yellow
Write-Host "开发环境配置:" -ForegroundColor Cyan
Get-Content "appsettings.Development.json" | Select-Object -First 15

Write-Host "`n生产环境配置:" -ForegroundColor Cyan  
Get-Content "appsettings.Production.json" | Select-Object -First 15

Write-Host "`n=== 测试完成 ===" -ForegroundColor Green
Write-Host "请检查输出结果确认环境配置是否正确加载。" -ForegroundColor White